package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: sky-take-out
 * @description:
 * @author: 酷炫焦少
 * @create: 2024-11-16 15:43
 **/
@RestController("adminDishController")
@RequestMapping("/admin/dish")
@Api(tags = "菜品相关接口")
@Slf4j
public class DishController {

    @Resource
    private DishService dishService;

    @PostMapping
    @ApiOperation("新增菜品")
    public Result<String> addDish(@RequestBody DishDTO dishDTO) {
        return dishService.addDish(dishDTO);
    }

    @GetMapping("/page")
    @ApiOperation("菜品列表")
    public Result<PageResult> page(DishPageQueryDTO dishPageQueryDTO) {
        return dishService.page(dishPageQueryDTO);
    }

    @DeleteMapping
    @ApiOperation("删除菜品")
    public Result<String> deleteDish(@RequestParam("ids") List<Long> ids) {
        return dishService.deleteDish(ids);
    }

    @GetMapping("{id}")
    @ApiOperation("查询某一菜品")
    public Result<DishDTO> getDishById(@PathVariable("id") Long id) {
        return dishService.getDishById(id);
    }

    @PostMapping("/status/{status}")
    @ApiOperation("修改菜品状态")
    public Result<String> editDishStatus(@PathVariable("status") Integer status,  Long id) {
        return dishService.editDishStatus(status, id);
    }

    @PutMapping
    @ApiOperation("修改菜品")
    public Result<String> editDish(@RequestBody DishDTO dishDTO) {
        return dishService.editDish(dishDTO);
    }

    @GetMapping("/list")
    @ApiOperation("根据分类查找菜品")
    public Result<List<DishVO>> list(Long categoryId) {
        return dishService.list(categoryId);
    }

}
